<meta charset="UTF-8">

<!-- 增删改查 -->
<div id="toolbar" class="btn-group">
	<button type="button" class="btn btn-default" onclick="classTable.btn_delete()">
		<span class="glyphicon glyphicon-remove"></span>删除
	</button>
</div>

<table id="borrowRecord">
	<thead>
		<tr>
			<th data-checkbox="true"></th>
			<th data-field="id" data-valign="middle" data-order= 'asc' data-sortable= 'true'  data-align="center" >id</th>
			<th data-field="reader" data-formatter="Readername" data-valign="middle" data-align="center" >借书人姓名</th>
			<th data-field="reader" data-formatter="Readerphone" data-valign="middle" data-align="center" >借书人电话</th>
			<th data-field="book" data-formatter="Bookname" data-valign="middle" data-align="center" >图书名称</th>
			<th data-field="book" data-formatter="BookCode" data-valign="middle" data-align="center" >图书编码</th>
			<th data-field="book" data-formatter="Booktype" data-valign="middle" data-align="center" >图书类型</th>
			<th data-field="applytime" data-valign="middle" data-align="center" >申请借书时间</th>
			<th data-field="borrowtime" data-valign="middle" data-align="center" >同意借书时间</th>
			<th data-field="givetime"  data-valign="middle" data-align="center" >归还时间</th>
			<th data-field="status"  data-valign="middle" data-align="center" >状态</th>
			<th data-field="operation"  data-valign="middle" data-align="center" >操作人用户名</th>
			
			<th data-valign="middle" data-align="center" data-formatter="AddFunctionAlty"  data-events="operateEvents">操作</th>
		</tr>
	</thead>
</table>

<script>
window.operateEvents = {
	      "click #TableEditor":function(ev,value,row,index){
	    	if(row.status=="申请中"){
			$.ajax({
				url:'borrowRecord/edit1',
				data:{id:row.id},
				type:'post',
				success:function(result){
					if(result.success){
						bootbox.alert("已同意");
						$("#borrowRecord").bootstrapTable("refresh");
					}else{
						bootbox.alert("同意失败");
					}
				}
			});
	    	}else if(row.status=="已同意"){
	    		bootbox.alert("该记录已同意，请勿重复操作");
	    	}else if(row.status=="已拒绝"){
	    		bootbox.alert("该记录已拒绝，请勿重复操作");
	    	}else if(row.status=="已归还"){
	    		bootbox.alert("该图书已归还，请勿重复操作");
	    	}
	    	
	      },
	      "click #TableEditor1":function(ev,value,row,index){
	    	  if(row.status=="申请中"){
	    	  $.ajax({
					url:'borrowRecord/edit2',
					data:{id:row.id},
					type:'post',
					success:function(result){
						if(result.success){
							bootbox.alert("已拒绝");
							$("#borrowRecord").bootstrapTable("refresh");
						}else{
							bootbox.alert("拒绝失败");
						}
					}
				});
	    	  }else if(row.status=="已同意"){
		    		bootbox.alert("该记录已同意，请勿重复操作");
		    	}else if(row.status=="已拒绝"){
		    		bootbox.alert("该记录已拒绝，请勿重复操作");
		    	}else if(row.status=="已归还"){
		    		bootbox.alert("该图书已归还，请勿重复操作");
		    	}
	      }
	 }
//使用函数，添加按钮
function AddFunctionAlty(value,row,index){
  return [
    '<button id="TableEditor" type="button" class = "btn btn-primary btn-sm">同意借书</button>',
    '<button id="TableEditor1" type="button" class = "btn btn-default btn-sm" >拒绝借书</button>'
  ].join('');
}

	var option = {
		url: 'borrowRecord/page1',
		urls: 'borrowRecord',
		addurl: 'edit'
	}
	var table = $("#borrowRecord");
	var classTable = new bootstrapTable(option, table);
	classTable.init();
	function Readername(value,row,index){
		  return value?value.name:'';
	}
	function Readerphone(value,row,index){
		  return value?value.phone:'';
	}
	function Bookname(value,row,index){
		  return value?value.bookName:'';
	}
	function BookCode(value,row,index){
		  return value?value.bookCode:'';
	}
	function Booktype(value,row,index){
		  return value?value.booktype.type	:'';
	}
</script>
